package com.topgay.service.chatting;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.topgay.dao.chatting.TestChattingDAO;
import com.topgay.domain.TestChatting;

@Service
public class TestChattingService {

	@Autowired
	private TestChattingDAO dao;
	
	public int sendMessage(String fromId, String toId, String message){
		
		int rowNum = selectMessageCount()+1;

		return dao.insertMessage(new TestChatting(rowNum, message, fromId, toId));
	}
	
	public int selectMessageCount(){
		
		List<TestChatting> tmpList= dao.selectAllMessage();
		int rowNum = 0;
		
		if(tmpList != null){
			rowNum = tmpList.size();
		}
		
		return rowNum;
	}
	
	public List<TestChatting> selectMessage(String myId){
		
		return dao.selectMessage(myId);
	}
	
}
